__author__ = 'Kerr Wang'

import struct
import time
import json
import asyncio
import http.client
import urllib
import logging
from config import *

def httpSend(host, url, port, data_str):
	conn = http.client.HTTPConnection(host, port, timeout = 5)
	data = {'data':data_str}
	headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "*/*"}
	params = urllib.parse.urlencode(data)
	conn.request("POST", url, params, headers)

	response = conn.getresponse()
	data = response.read()
	conn.close()
	return data

def httpTimeValidGet(host, url, port):
	if TIME_WINDOW == 1:
		conn = http.client.HTTPConnection(host,port,timeout = 1)
		conn.request(method="GET", url=url)
		response = conn.getresponse()
		res= response.read()
		if res == b'true':
			return True
		else:
			return False
	else:
		return True

def main():
	if True == httpTimeValidGet(OBJ_HOST,TIMEVLIAD_URL,PORT):
		print("true")
	
if __name__ == '__main__':
	main()






